<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核结果导入列表</title>
    <link href="../../layui/css/layui.css" rel="stylesheet">
    <link href="../../static/css/style.css" rel="stylesheet">
    <script src="../../static/js/jquery.min.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="../../layui/layui.js"></script>
    <script src="../../static/js/base.js"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/avalon.js"></script>
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body>


<div class="layui-fluid" ms-controller="test">
    <div class="layui-card content-wrap">
        <!--查询-->
        <!--<div class="layui-form layui-card-header layuiadmin-card-header-auto">-->
        <form class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">流水号</label>
                        <div class="layui-input-block">
                            <input type="text" id="serialNumber" placeholder="请输入流水号" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-col-sm4">
                        <label class="layui-form-label">省份</label>
                        <div class="layui-input-block">
                            <select lay-filter="provinceSelect" id='optProvince' lay-verify="required">
                                <option value="0">请选择</option>
                                <option ms-attr="{value: el.code}" ms-for="($index, el) in @provlist">{{el.name}}</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">市区</label>
                        <div class="layui-input-block">
                            <select lay-filter="regionSelect" id='optCity' lay-verify="required" name="cityCode">
                                <option value="0">请选择</option>
                                <option ms-attr="{value: el.code}" ms-for="($index, el) in @regionlist">{{el.name}}</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">导入时间起</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="fromTime" placeholder="导入时间起" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-sm4">
                        <label class="layui-form-label">导入时间至</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="toTime" placeholder="导入时间止" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-sm4">

                        <a id="doSearch" class="layui-btn add_btn"><i class="layui-icon layui-icon-search"></i>搜索</a>
                        <button type="reset" class="layui-btn delete_btn"><i class="layui-icon layui-icon-delete"></i>清空</button>
                        <a id="doImport" class="layui-btn add_btn"><i class="layui-icon layui-icon-search"></i>导入</a>
                    </div>

                </div>
            </div>
        </form>


        <!--数据列表展示-->
        <div>
            <script type="text/html" id="optToolbar">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-useradmin delete_btn" lay-event="delRecord"><i class="layui-icon layui-icon-delete"></i>删除</button>
                    <button class="layui-btn layuiadmin-btn-useradmin add_btn" lay-event="viewRecord">查看</button>
                </div>
            </script>

            <table class="layui-hide" id="dataListTable"
                   lay-filter="active"></table>
        </div>


    </div>
</div>


</body>

<script>

    var table;
    var tableObj;
    var form;
    var vm = avalon.define({
        $id: "test",
        fromTime: '',
        toTime: '',
        provlist: [],
        regionlist: [],
        provinceid:'',
        cityid:'',
        //  查询省市区
        getprovlist: function () {
            ax.post({
                url:schoolWebUrl +  '/api/captcha/getRegionProvince',
                contentType: "application/x-www-form-urlencoded",
                data: '',
                success: function (r) {
                    vm.provlist = r.data;
                    vm.provinceid = "";
                    // vm.provinceid = r.data[0].code;
                    // vm.getRegionlist();
                    setTimeout(function () {
                        form.render('select');
                    },200);
                },
            });
        },
        // 获取市
        getRegionlist: function () {
            ax.post({
                url: schoolWebUrl + '/api/captcha/getRegionCode',
                contentType: "application/x-www-form-urlencoded",
                data: { "code": vm.provinceid },
                success: function (r) {
                    // vm.cityid = r.data[0].code;
                    vm.cityid = "";
                    vm.regionlist = r.data;
                    setTimeout(function () {
                        form.render('select');
                    },200);
                },
            });
        },
    });
    vm.$watch('onReady', function () {
        //获取省市区
        console.log(1)
        vm.getprovlist();

    });

    layui.use(['table','form','laydate','layer','element','upload'], function() {
        table = layui.table;
        form = layui.form;
        var $ = layui.$,
            layDateFrom = layui.laydate,
            layDateTo = layui.laydate,
            importFile = layui.upload,
            layer=layui.layer;

        // 初始化日期控件
        var fromTime = layDateFrom.render({
            elem: '#fromTime',
            max:'nowTime',//默认最大值为当前日期
            done:function(value, date) {
                if(date.hasOwnProperty("year")) {
                    toTime.config.min={
                        year:date.year,
                        month:date.month-1,//关键
                        date:date.date,
                        hours:date.hours,
                        minutes:date.minutes,
                        seconds:date.seconds
                    };
                }
            }
        });
        var toTime = layDateTo.render({
            elem: '#toTime',
            max:'nowTime',//默认最大值为当前日期
            done:function(value, date) {
                if(date.hasOwnProperty("year")) {
                    fromTime.config.max={
                        year:date.year,
                        month:date.month-1,//关键
                        date:date.date,
                        hours:date.hours,
                        minutes:date.minutes,
                        seconds:date.seconds
                    };
                }
            }
        });

        //省改变
        form.on('select(provinceSelect)', function (data) {
            vm.provinceid = data.value;
            vm.getRegionlist();
        });
        // 市改变
        form.on('select(regionSelect)', function (data) {
            vm.cityid = data.value;
        });

        // 初始化上传控件
        ax.upload({
            elem: '#doImport' //绑定元素
            ,url: backendWebUrl + '/api/student/review/importCheckResult'//上传接口
            ,accept:"file"    // images（图片）、file（所有文件）、video（视频）、audio（音频）
            ,exts:'xls|xlsx'   // 允许上传的文件后缀。一般结合 accept 参数类设定
            ,data:{
                cityCode:function () {
                    return vm.cityid;
                }
            }
            ,before: function(obj){
                layer.msg('审核结果导入中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            }
            ,done: function(res){
                layer.close(layer.msg());//关闭上传提示窗口
                if(res.code == 0) {
                    //上传完毕回调
                    layer.msg("导入成功");
                    searchData();
                } else {
                    if(res.message != null && res.message != "") {
                        layer.msg(res.message);
                    } else {
                        layer.msg("导入失败");
                    }
                }

            }
            ,error: function(){
                //请求异常回调
                layer.msg("上传失败");
            }
        });

        tableObj = ax.VTable({
            id: 'loadDataList',
            elem : '#dataListTable',
            url : backendWebUrl + '/api/student/review/listImportRecord',
            toolbar: '#optToolbar',
            title:'导入记录列表',
            cols : [ [
                {type : 'checkbox', fixed : 'left' },
                {type: 'numbers', width : 80, title : '序号', fixed : 'left'},
                {field : 'serialNumber', title : '流水号', width : 200, fixed : 'left' },
                {field : 'dataCount', width : 100, title : '数量' },
                {field : 'optCityName', minWidth : 200, title : '省市' },
                {field : 'optTime', width : 200, title : '导入时间'}
                ] ]

        });

        $('#doSearch').on('click', function(){
            searchData();
        });

        //头工具栏事件
        table.on('toolbar()', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'delRecord':
                    var data = checkStatus.data;
                    if(data.length<=0) {
                        layer.open({
                            title: '信息提示'
                            ,content: '请选择删除的数据！'
                        });
                        break;
                    }
                    layer.confirm('确定需要删除选中的导入记录！', function (index) {
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(data[i].id);
                        }
                        delRecord(ids.join(","));
                    })

                    break;
                case 'viewRecord':
                    var data = checkStatus.data;
                    if(data.length<=0) {
                        layer.open({
                            title: '信息提示'
                            ,content: '请选择查看的数据！'
                        });
                        break;
                    }
                    window.location.href='checkResultInfo.html?id='+ data[0].id
                    break;
            };
        });

    });

    function searchData() {
        //执行重载
        tableObj.reload({
            page : {
                curr: 1 //重新从第 1 页开始
            },
            where : {
                serialNumber: $('#serialNumber').val(),
                provinceCode: vm.provinceid,
                cityCode: vm.cityid,
                fromTime : $('#fromTime').val(),
                toTime : $('#toTime').val()
            }
        });
    }

    //删除通知
    function delRecord(ids) {
        var data={ids:ids};
        ax.get({
            url:backendWebUrl + "/api/student/review/deleteImportRecord",
            data:data,
            success:function (res) {
                if(res.code == 0) {
                    layer.msg("删除成功");
                    searchData();
                } else {
                    layer.msg(res.msg);
                }
            },
            error : function(request) {
                layer.msg("系统错误，联系管理员");
            }
        });
    }
</script>
</html>